package com.Langrui.service.impl;

import com.Langrui.dao.ArticleDao;
import com.Langrui.entity.Article;
import com.Langrui.service.ArticleService;
import lore.miniwechat.utils.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;


@Service
public class ArticleSeviceImpl implements ArticleService {

    @Autowired
    ArticleDao dao;

    @Autowired
    IdWorker idWorker;

    @Override
    public void save(Article article) {
        //id前端不会传来
        article.setId(String.valueOf(idWorker.nextId()));
        dao.save(article);
    }

    public Article findById(String id) {
        Optional<Article> byId = dao.findById(id);
        if (byId.isPresent()){
            return byId.get();
        }else{
            throw new RuntimeException("id对应的记录不存在");
        }
    }

    public Article deleteById(String id) {
        return null;
    }
}
